package org.wesync.mosquito;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class Client1 {

public static void main(String[] args) throws IOException {
	int bport=29140;
	DatagramSocket socket=null;
	try {
	socket = new DatagramSocket(bport);
	} catch (IOException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
	}

	DatagramPacket packet;
	byte[] buffer = new byte[256];
	packet = new DatagramPacket(buffer,buffer.length);
	socket.receive(packet);
	
	String received = new String (packet.getData());
	
	socket.close();
	
	Socket kkSocket = null;
	PrintWriter out = null;
	BufferedReader in = null;
	int gport=29141;
	try {
	kkSocket = new Socket (received,gport);
	out = new PrintWriter(kkSocket.getOutputStream(), true);
	in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream()));
	} catch (UnknownHostException e) {
	System.err.println("Don't know about host: localhost");
	System.exit(1);
	} catch (IOException e) {
	System.err.println("Couldn't get I/O for the connection to: taranis.");
	System.exit(1);
	}
	
	while(true){
		out.println("Client 1");
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
		// TODO Auto-generated catch block
			e.printStackTrace();
		}
		}
	}
}